package team.stride.database.crud.music;

import java.util.List;

import team.stride.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MusicAdapter extends BaseAdapter
{
	private BDMusicActivity activity;
	private List<MusicItem> musicList;

	public MusicAdapter(BDMusicActivity activity, List<MusicItem> mapslist)
	{
		this.activity = activity;
		this.musicList = mapslist;
	}

	public int getCount()
	{
		return musicList.size();
	}

	public MusicItem getItem(int position)
	{
		return musicList.get(position);
	}

	public long getItemId(int position)
	{
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup viewGroup)
	{
		final MusicItem entry = musicList.get(position);
		if (convertView == null)
		{
			LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.bd_music_row, null);
		}
		
		TextView musicSong = (TextView) convertView.findViewById(R.id.musicSong);
		musicSong.setText(entry.getSong());

		TextView musicSinger = (TextView) convertView.findViewById(R.id.musicSinger);
		musicSinger.setText("" + entry.getSinger());
		
		TextView musicPlaylist = (TextView) convertView.findViewById(R.id.musicPlaylist);
		musicPlaylist.setText("" + entry.getPlaylist());

		TextView musicFile = (TextView) convertView.findViewById(R.id.musicFile);
		musicFile.setText("" + entry.getFile());
		
		TextView musicDetails = (TextView) convertView.findViewById(R.id.musicDetails);
		musicDetails.setText("" + entry.getDetails());

		ImageView musicImg = (ImageView) convertView.findViewById(R.id.musicImg);
		musicImg.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				activity.showDialog(BDMusicActivity.MODIFY_DIALOG, entry);
			}
		});
		return convertView;
	}
}
